package task;
class Add{
    int sum1;
    int sum2;
    public void fun1(int n){
        sum1 += n;
    }
    public void fun2(int n){
        sum2 += n;
    }
}


public class Test1 {
    public static void main(String[] args) throws InterruptedException {
        long start = System.currentTimeMillis();
        int[] arr = new int[10000000];
        Add add = new Add();
        for (int i = 0; i < 10000000; i++) {
            arr[i] = (int)(Math.random()*100) + 1;
        }
        Thread t1 = new Thread(() -> {
            for (int i = 0; i < 10000000; i+=2) {
                add.fun1(arr[i]);
            }
        });
        Thread t2 = new Thread(() -> {
            for (int i = 1; i < 10000000; i+=2) {
                add.fun2(arr[i]);
            }
        });
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        long end = System.currentTimeMillis();
        System.out.println(add.sum2 + add.sum1);
        System.out.println(end - start);
    }
}
